<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用户信息</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">

   function  del(id) {
	    $.ajax({
            type: 'POST',
            url: '/del',
            data: {"id":id},
            success: function (data) {
            	var da=eval('(' + data + ')');
            	  if(da.resul==1){
            		  alert("删除成功");
            		  window.location.href='/index';
            	  }
            	  else{
            		  alert("删除失败");
            	  }
            },
            error: function () {
                alert("出错了,请重试!");
            }
        });
}
</script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">weirdor</a>
    </div>
   
    <ul class="nav navbar-nav navbar-right">
    
    
   <c:choose>
   <c:when test="${currentUser==null}">
     <li><a href="#"><span class="glyphicon glyphicon-user"></span> 注册</a></li>
       <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> 登录</a></li>

   </c:when>
   <c:otherwise>
    <li class="dropdown">
            <shiro:user>  
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
           <span class="glyphicon glyphicon-user"></span> <shiro:principal/><b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="/logout">退出</a></li>
                </ul>
                </shiro:user>
            </li>
   </c:otherwise>
   </c:choose>   
    </ul>
  </div>
</nav>

<form class="form-horizontal" id="from1">
<input type="hidden" name="id" value="${user.id}">
<shiro:hasRole name="管理员">
	<div class="form-group">
	
		<label for="firstname" class="col-sm-2 control-label">用户名</label>
		<div class="col-sm-10">
			<input type="text" class="form-control" name="username" value="${user.username}"
				   placeholder="请输入用户">
		</div>
	</div>
	</shiro:hasRole>
	<div class="form-group">
		<label for="lastname" class="col-sm-2 control-label">密码</label>
		<div class="col-sm-10">
			<input type="text" class="form-control" name="password"<shiro:hasRole name="管理员">  value="${user.password}"  </shiro:hasRole> placeholder="请输入密码">
		</div>
	</div>
	<shiro:hasRole name="管理员">
	<div class="form-group">
    <label for="name" class="col-sm-2 control-label">权限</label>
    <div class="col-sm-10">
    <select class="form-control"  name="roleld">
    <c:forEach items="${role}" var="roles">
      <option value="${roles.id}" <c:if test="${roles.id==user.roleld}"> selected="selected" </c:if> >${roles.roleName}</option>
       </c:forEach>
    </select>
    </div>
    </div>
    </shiro:hasRole>
	<div class="form-group">
		<div class="col-sm-offset-2 col-sm-10">
			<button type="button" class="btn btn-default" onclick="sub();">保存</button>
		</div>
	</div>
</form>

</body>
<script>
    function sub() {
        $.ajax({
            type: 'POST',
            url: '/edit',
            data: $('#from1').serialize(),
            dataType: 'json',
            success: function (data) {
          	  if(data.resul==1){
          		  alert("成功");
          		  window.location.href='/index';
          	  }
          	  else{
          		  alert("失败");
          	  }
            },
            error: function () {
                alert("出错了,请重试!");
            }
        });
    }
</script>
</html>